package com.ry.novel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ry.novel.model.dto.NewsInfo;
import com.ry.novel.model.dto.condition.NewsQuery;
import com.ry.novel.model.entity.News;
import com.ry.novel.model.resp.Result;
import com.ry.novel.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ry
 * @since 2022-04-10 15:44
 **/
@RequestMapping("/news")
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;

    @PostMapping("/queryNews")
    public Result<Page<NewsInfo>> queryNews(@RequestBody NewsQuery newsQuery){
        Page<NewsInfo> newsInfoPage = newsService.queryNews(newsQuery);

        return Result.ok(newsInfoPage);
    }

    @PostMapping("/addNews")
    public Result<Void> addNews(@RequestBody NewsInfo info){
        newsService.addNews(info);

        return Result.ok();
    }

    @PostMapping("/updateNews")
    public Result<Void> updateNews(@RequestBody NewsInfo info){
        newsService.updateNews(info);

        return Result.ok();
    }

    @PostMapping("/deleteNews")
    public Result<Void> deleteNews(@RequestParam("id")Long id){
        newsService.deleteNews(id);

        return Result.ok();
    }
}
